package com.suoluo.zenadmin.dao.dest;

import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;

import com.suoluo.zenadmin.vo.dest.DestFeatureCategoryVO;

@DAO
public interface DestFeatureCategoryDAO {
	@SQL("select t1.t_feature_category_id,t1.t_feature_category_name, "
			+ "t1.t_feature_category_order,t2.t_feature_category_name parentName,"
			+ "t1.t_feature_category_color,t1.t_feature_category_desc, "
			+ "t1.t_feature_category_orig_img,t1.t_default_pause_time from "
			+ "tb_dest_feature_category t1 left join tb_dest_feature_category t2 "
			+ "on t1.t_feature_parent_category_id = t2.t_feature_category_id "
			+ " order by t1.t_feature_category_order")
	public List<DestFeatureCategoryVO> findListDestFeatureCategory();

	@ReturnGeneratedKeys
	@SQL("insert into tb_dest_feature_category(t_feature_category_name,"
			+ "t_feature_category_order,t_feature_parent_category_id,t_feature_category_color,"
			+ "t_feature_category_desc,t_feature_category_orig_img,t_default_pause_time,root_viewable) "
			+ "values(:1.featureCategoryName,:1.featureCategoryOrder,:1.featureParentCategoryId,"
			+ ":1.featureCategoryColor,:1.featureCategoryDesc,:1.featureCategoryOrigImg,"
			+ ":1.defaultPauseTime,:1.rootViewable)")
	public int saveDestFeatureCategory(DestFeatureCategoryVO category);

//	@SQL("select t_feature_category_id,t_feature_category_name "
//			+ "from tb_dest_feature_category where t_feature_parent_category_id = 0 "
//			+ " and t_feature_category_order != -1")
//	public List<DestFeatureCategoryPOJO> findListParentCategory();

	@SQL("select max(t_feature_category_order) from tb_dest_feature_category")
	public Integer findFeatureCategoryMaxOrder();

	@SQL("update tb_dest_feature_category set t_feature_category_order=:1.oldOrder "
			+ "where t_feature_category_order=:1.featureCategoryOrder")
	public void updateFeatureCategoryByOrderId(DestFeatureCategoryVO categoryVO);

	@SQL("update tb_dest_feature_category set t_feature_category_name=:1.featureCategoryName,"
			+ "t_feature_parent_category_id=:1.featureParentCategoryId," +
					"t_feature_category_color=:1.featureCategoryColor,"
			+ "t_feature_category_order=:1.featureCategoryOrder," +
					"t_feature_category_desc=:1.featureCategoryDesc,"
			+ "t_feature_category_orig_img=:1.featureCategoryOrigImg," +
					"t_default_pause_time=:1.defaultPauseTime,root_viewable=:1.rootViewable "
			+ " where t_feature_category_id=:1.featureCategoryId")
	public void updateDestFeatureCategory(DestFeatureCategoryVO categoryVO);

	@SQL("update tb_dest_feature_category set t_feature_category_color=:1.featureCategoryColor,"
			+ "t_feature_category_desc=:1.featureCategoryDesc,"
			+ "t_feature_category_orig_img=:1.featureCategoryOrigImg,"
			+ "t_default_pause_time=:1.defaultPauseTime  "
			+ " where t_feature_category_id=:1.featureCategoryId")
	public void updateSpecialCategory(DestFeatureCategoryVO categoryVO);

	@SQL("delete from tb_dest_feature_category where t_feature_category_id = :1")
	public void deleteDestFeatureCategory(int categoryId);

	@SQL("select * from tb_dest_feature_category where t_feature_category_id=:1")
	public DestFeatureCategoryVO findDestFeatureCategoryById(int categoryId);

	@SQL("select t_default_pause_time from tb_dest_feature_category "
			+ "where t_feature_category_id=:1")
	public int findCategoryDefaultPauseTime(int featureCategoryId);

	@SQL("select * from tb_dest_feature_category")
	public List<DestFeatureCategoryVO> findAllCategory();

	
	/**
	 * 查询根类别，过滤掉指定ID的跟类别
	 * @param id
	 * @return
	 */
	@SQL("select * from  tb_dest_feature_category "
			+ "where t_feature_parent_category_id = 0 and root_viewable = 1 and t_feature_category_id <> :1  order by t_feature_category_order asc")
	public List<DestFeatureCategoryVO> findRootCategoryWithoutId(int id);

	@SQL("SELECT count(feature_id) FROM tb_dest_feature2 where feature_category_id = :1")
	public int findDestFeatureCountByCategoryId(int categoryId);
	
	@SQL("select count(*) from tb_home_category where t_feature_category_id =:1")
	public int findHomeCountByCategoryId(int categoryId);
	
	@SQL("select count(*) from tb_dest_feature_category where t_feature_parent_category_id =:1")
	public int findParentCategoryCountByCategoryId(int categoryId);
	
	@SQL("select count(*) from tb_dest_feature_item2 where feature_category_id =:1")
	public int findDestFeatureItemCountByCategoryId(int categoryId);
	
	@SQL("select count(*) from tb_home_style_item where t_feature_category_id =:1")
	public int findStyleCountByCategoryId(int categoryId);
}
